<template>
	<view class="container">
		<m-user-req v-for="(item,index) in userList" :key="index" :item="item" @click="onClick"/>
		<!-- <van-tabs type="card" :color="primaryColor">
		  <van-tab title="用户申请">
		  </van-tab>
		  <van-tab title="司机申请"></van-tab>
		</van-tabs> -->
		
		<van-dialog id="van-dialog" />
		<van-toast id="van-toast" />
	</view>
</template>

<script>
	import utils from '@/common/utils.js'
	import Dialog from '@/wxcomponents/dialog/dialog'
	import Toast from '@/wxcomponents/toast/toast'
	export default {
		data() {
			return {
				primaryColor: getApp().globalData.primaryColor,
				userList:[],
				pageObj:{
					page:1,
					pagesize:15
				}
			}
		},
		onLoad() {
		},
		async onShow() {
			await this.resetUserList()
		},
		async onReachBottom() {
			this.pageObj.page++
			await this.getUserList()
		},
		methods: {
			async getUserList(){
				try{
					const reqData = {
						token: uni.getStorageSync('userinfo').token,
						filter:{
							userStatus: 'registed',
							isDel: 0
						},
						...this.pageObj
					}
					if(!this.isThird){
						reqData.filter.role = 'user'
					}else{
						reqData.filter.role = 'driver'
					}
					const rspData = await utils.req('/user/getAllUserList', reqData)
					this.userList = [...this.userList, ...rspData.list]
				}catch(e){
					Toast(e.msg)
					console.error(e)
				}
			},
			async resetUserList(){
				this.userList = []
				this.pageObj.page = 1
				await this.getUserList()
			},
			onClick(obj){
				const data = encodeURIComponent(JSON.stringify(obj))
				uni.navigateTo({
					url:`../user-req-detail/user-req-detail?data=${data}`
				})
			}
		},
		computed:{
			isThird(){
				return uni.getStorageSync('userinfo').companyId != 1
			}
		}
	}
</script>

<style scoped lang="scss">
view {
		--tabs-default-color: $uni-color-primary
	}
	.container {
		padding-top: 20px;
		padding-bottom: 20px;
	}
</style>
